﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PubSubLite.IOC
{
    /// <summary>
    /// Represents a type mapping.
    /// </summary>
    /// <typeparam name="T">The abstract type (i.e. an interface or abstract class)</typeparam>
    /// <typeparam name="T2">The implementing type</typeparam>
    public class TypeMapping<T, T2> : ITypeMapping
    {
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Name of the mapping</param>
        public TypeMapping(string name)
        {
            if (!(typeof(T).IsAbstract || typeof(T).IsInterface))
            {
                throw new InvalidOperationException("Type parameter T must be an abstract class or an interface");
            }
            if (!(typeof(T).IsAssignableFrom(typeof(T2))))
            {
                throw new InvalidOperationException("Type parameter T1 must be assignable from T2!");
            }
            _abstractType = typeof(T);
            _implementingType = typeof(T2);
            Name = name;
        }

        private Type _abstractType;
        private Type _implementingType;

        /// <summary>
        /// The abstract type
        /// </summary>
        public Type AbstractType
        {
            get { return _abstractType; }
        }

        /// <summary>
        /// The implementing type
        /// </summary>
        public Type ImplementingType
        {
            get { return _implementingType; }
        }

        /// <summary>
        /// Name of the mapping
        /// </summary>
        public string Name
        {
            get;
            private set;
        }
    }
}
